﻿using System.Collections.Generic;
using Calimbra.Runtime.Contracts;
using Calimbra.Runtime.Data;
using Calimbra.Runtime.Functions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Calimbra.Runtime.Test
{
    [TestClass]
    public class Map_message_to_input_ports_test
    {
        [TestMethod]
        public void In_out()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream(".in", ".out")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message(".in", "Test message"));

            Assert.AreEqual(".out", result.Port.Name);
        }

        [TestMethod]
        public void In_A()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream(".in", "A")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message(".in", "Test message"));

            Assert.AreEqual("A", result.Port.Name);
        }

        [TestMethod]
        public void In_AIn()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream(".in", "A.in")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message(".in", "Test message"));

            Assert.AreEqual("A.in", result.Port.Name);
        }

        [TestMethod]
        public void In_Aname()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream(".in", "A.name")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message(".in", "Test message"));

            Assert.AreEqual("A.name", result.Port.Name);
        }

        [TestMethod]
        public void A_B()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream("A", "B")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message("A", "Test message"));

            Assert.AreEqual("B", result.Port.Name);
        }

        [TestMethod]
        public void AIn_BIn()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream("A.in", "B.in")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message("A.in", "Test message"));

            Assert.AreEqual("B.in", result.Port.Name);
        }

        [TestMethod]
        public void AName_B()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream("A.name", "B")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message("A.name", "Test message"));

            Assert.AreEqual("B", result.Port.Name);
        }

        [TestMethod]
        public void A_BName()
        {
            var target = new Map_message_to_input_ports();
            target.Inject(new List<IStream> {new Stream("A", "B.name")});
            IMessage result = null;
            target.Result += output => result = output;

            target.Process(new Message("A", "Test message"));

            Assert.AreEqual("B.name", result.Port.Name);
        }
    }
}